//
//  WBVistorView.swift
//  新浪微博
//
//  Created by 陈飞宇 on 2020/11/18.
//

import UIKit

//访客视图
class WBVistorView: UIView {
    
    var visitorInfo : [String : String]?{
        didSet{
            
            guard let imageName = visitorInfo?["imageName"], let message = visitorInfo?["messagge"] else  {
                 return;
            }
            
            tipLabel.text = message;
            if imageName == "" {
                return;
            }
            iconView.image = UIImage (named: imageName);
            hourseView.isHidden = true;
            maskIconView.isHidden = true;
        }
    }

    private lazy var iconView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    //遮罩
    private lazy var maskIconView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))

    
    private lazy var hourseView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    

    private lazy var tipLabel : UILabel = UILabel.cz_label(withText: "关注一些人,回这里看看有些什么让你惊喜的人", fontSize: 14, color: UIColor.darkGray)
    
    private lazy var registerButton : UIButton  = UIButton.cz_textButton("注册", fontSize: 16, normalColor: UIColor.orange, highlightedColor: UIColor.black , backgroundImageName: "common_button_white_disable")
    
    private lazy var loginButton : UIButton  = UIButton.cz_textButton("登录", fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.black , backgroundImageName: "common_button_white_disable")
  
 ///   MARK: 设置访客视图信息
    
    /// 使用字典设置访客视图的信息 ]
    /// - Parameter dict: [ImageName / message]
    func setUpInfo(dict: [String : String] ){
    
    
        
        
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame);
    
        setUpUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   
  
}
extension WBVistorView{

    func setUpUI() {
        
        backgroundColor = UIColor.cz_color(withHex: 0xEDEDED);
            
        addSubview(iconView);
        addSubview(maskIconView);
        addSubview(hourseView);
        addSubview(tipLabel);
        addSubview(registerButton);
        addSubview(loginButton);
        
        tipLabel.textAlignment = .center;
        
        
        for v in subviews {
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        //布局
        addConstraint(NSLayoutConstraint(item: iconView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: iconView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: -60))
        
        //小房子布局
        addConstraint(NSLayoutConstraint(item: hourseView, attribute: .centerX, relatedBy: .equal, toItem: iconView, attribute: .centerX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: hourseView, attribute: .centerY, relatedBy: .equal, toItem: iconView, attribute: .centerY, multiplier: 1.0, constant: 0))
        
        //标签
        addConstraint(NSLayoutConstraint(item: tipLabel, attribute: .centerX, relatedBy: .equal, toItem: iconView, attribute: .centerX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: tipLabel, attribute: .top, relatedBy: .equal, toItem: iconView, attribute: .bottom, multiplier: 1.0, constant: 20))
        
        //注册按钮
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .left, relatedBy: .equal, toItem: tipLabel, attribute: .left, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .top, relatedBy: .equal, toItem: tipLabel, attribute: .bottom, multiplier: 1.0, constant: 20))
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 100))
        
        //登录按钮
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .right, relatedBy: .equal, toItem: tipLabel, attribute: .right, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .top, relatedBy: .equal, toItem: tipLabel, attribute: .bottom, multiplier: 1.0, constant: 20))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 100))
        
        
        
        //遮罩
        let viewDic = ["maskIconView":maskIconView,
                       "registerButton":registerButton
        ];
        let metrics = ["spacing": -35];
        
        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[maskIconView]-0-|", options: [], metrics: nil, views: viewDic))
        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[maskIconView]-(spacing)-[registerButton]", options: [], metrics: metrics, views: viewDic))


    }

}
